package com.wuliuqi.yaohuoubb;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.Toast;

import com.wuliuqi.yaohuoubb.BaseActivity.BaseActivity;

import java.util.ArrayList;

public class MainActivity extends BaseActivity {
    private Spinner spinner;
    private ArrayList<String> list;
    private boolean exit = true;
    static EditText edit_1;
    static EditText edit_2;
    static EditText edit_3;
    private Button btn_build;
    private String str = "";
    private int pos = 0;
    private ArrayAdapter adapter;

    @SuppressLint("ResourceType")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        spinner = findViewById(R.id.SelectBox);
        edit_1 = findViewById(R.id.edit_1);
        edit_2 = findViewById(R.id.edit_2);
        edit_3 = findViewById(R.id.edit_3);
        toast("长按按钮可清空所有输入框");
        btn_build = findViewById(R.id.btn_build);
        getArry();
        marryClick();
        btn_build.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                switch (pos){
                    case 0:
                        break;
                    case 1:
                        str =  StringGeneration.gn_Url(edit_1,edit_2);
                        break;
                    case 2:
                        str = StringGeneration.gn_ImgUrl(edit_1);
                        break;
                    case 3:
                        str = StringGeneration.gn_ImgUrl2(edit_1,edit_2);
                        break;
                    case 4:
                        str = StringGeneration.gn_Music(edit_1);
                        break;
                    case 5:
                        str = StringGeneration.gn_Movie(edit_1);
                        break;
                    case 6:
                        str = StringGeneration.gn_Call(edit_1);
                        break;
                    case 7:
                        str = StringGeneration.gn_Sms(edit_1,edit_2,edit_3);
                        break;
                    case 8:
                        str = "[tab]";
                        break;
                    case 9:
                        str = "[br]";
                        break;
                    case 10:
                        str = "[hr]";
                        break;
                    case 11:
                        str = StringGeneration.gn_I(edit_1);
                        break;
                    case 12:
                        str = StringGeneration.gn_Strike(edit_1);
                        break;
                    case 13:
                        str = StringGeneration.gn_TextColor(edit_1,edit_2);
                        break;
                    case 14:
                        str = "[left]";
                        break;
                    case 15:
                        str = "[right]";
                        break;
                    case 16:
                        str = "[center]";
                        break;
                    case 17:
                        str = StringGeneration.gn_U(edit_1);
                        break;
                    case 18:
                        str = StringGeneration.gn_B(edit_1);
                        break;
                    case 19:
                        str = StringGeneration.gn_codo(edit_1);
                        break;
                    case 20:
                        str = "[userid]";
                        break;
                    case 21:
                        str = "[money]";
                        break;
                    case 22:
                        str = "[classname]";
                        break;
                    case 23:
                        str = "[title]";
                        break;
                    case 24:
                        str = "[online]";
                        break;
                    case 25:
                        str = "[now]";
                        break;
                    case 26:
                        str = "[year]";
                        break;
                    case 27:
                        str = "[month]";
                        break;
                    case 28:
                        str = "[day]";
                        break;
                    case 29:
                        str = "[hour]";
                        break;
                    case 30:
                        str = "[minute]";
                        break;
                    case 31:
                        str = "[second]";
                        break;
                    case 32:
                        str = "[date]";
                        break;
                    case 33:
                        str = "[time]";
                        break;
                    case 34:
                        str = "[weekday]";
                        break;
                    case 35:
                        str = "[ttcc]";
                        break;
                    case 36:
                        str = "[hello]";
                        break;
                    case 37:
                        str = StringGeneration.gn_Tq(edit_1);
                        break;
                    case 38:
                        str = "[ui]1[/ui]";
                        break;
                    case 39:
                        str = "[ui]2[/ui]";
                        break;
                    case 40:
                        str = "[ui]3[/ui]";
                        break;
                    case 41:
                        str = "[ui]4[/ui]";
                        break;
                    case 42:
                        str = "[ui]5[/ui]";
                        break;
                    case 43:
                        str = "[ui]6[/ui]";
                        break;
                    case 44:
                        str = "[ui]7[/ui]";
                        break;
                    case 45:
                        str = "[ui]8[/ui]";
                        break;
                    case 46:
                        str = "[ui]9[/ui]";
                        break;
                    case 47:
                        str = "[ui]10[/ui]";
                        break;
                    case 48:
                        str = "[ui]11[/ui]";
                        break;
                    case 49:
                        str = "[ui]12[/ui]";
                        break;
                    case 50:
                        str = "[ui]13[/ui]";
                        break;
                    case 51:
                        str = "[ui]14[/ui]";
                        break;
                    case 52:
                        str = "[ui]15[/ui]";
                        break;
                    case 53:
                        str = "[ui]16[/ui]";
                        break;
                    case 54:
                        str = "[ui]17[/ui]";
                        break;
                    case 55:
                        str = "[ui]18[/ui]";
                        break;
                    case 56:
                        str = "[ui]19[/ui]";
                        break;
                    case 57:
                        str = "[ui]20[/ui]";
                        break;
                    case 58:
                        str = "[ui]21[/ui]";
                        break;
                    case 59:
                        str = "[ui]22[/ui]";
                        break;
                    case 60:
                        str = "[ui]23[/ui]";
                        break;
                    case 61:
                        str = "[ui]24[/ui]";
                        break;
                    case 62:
                        str = "[ui]25[/ui]";
                        break;
                    case 63:
                        str = "[ui]26[/ui]";
                        break;
                }
             toast(str);
              putTextIntoClip(str);
             str="";
//             toast(pos+"");
            }
        });
        btn_build.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View view) {
                edit_1.setText("");
                edit_2.setText("");
                edit_3.setText("");
                toast("已清空");
                return true;
            }
        });
    }

    public void getArry(){
        String[] stringArray = getResources().getStringArray(R.array.selectBox);
        list = new ArrayList<String>();
        for (String str : stringArray) {
            list.add(str);
        }
    }

    public void marryClick(){
        adapter = new ArrayAdapter<String>(this,R.layout.support_simple_spinner_dropdown_item,list);
        spinner.setAdapter(adapter);
        spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
                pos = i;
                switch (i){
                    case 0:;
                        dis0();
                        break;
                    case 1:
                        dis2();
                        e1(R.string.text_wl);
                        e2(R.string.text_text);
                        break;
                    case 2:
                        dis1();
                        e1(R.string.img_wl);
                        break;
                    case 3:
                        dis2();
                        e1(R.string.img_wl);
                        e2(R.string.img_wl2);
                        break;
                    case 4:
                        dis1();
                        e1(R.string.img_wl_music);
                        break;
                    case 5:
                        dis1();
                        e1(R.string.img_wl_movie);
                        break;
                    case 6:
                        dis1();
                        e1(R.string.text_tel);
                        break;
                    case 7:
                        dis3();
                        e1(R.string.text_tel);
                        e2(R.string.text_sms_text);
                        e3(R.string.text_sms_web);
                        break;
                    case 8:
                        dis0();
                        break;
                    case 9:
                        dis0();
                        break;
                    case 10:
                        dis0();
                        break;
                    case 11:
                        dis1();
                        e1(R.string.text_text);
                        break;
                    case 12:
                        dis1();
                        e1(R.string.text_text);
                        break;
                    case 13:
                        dis2();
                        e1(R.string.text_text_color);
                        e2(R.string.text_text);
                        break;
                    case 14:
                        dis0();
                        break;
                    case 15:
                        dis0();
                        break;
                    case 16:
                        dis0();
                        break;
                    case 17:
                        dis1();
                        e1(R.string.text_text_u);
                        break;
                    case 18:
                        dis1();
                        e1(R.string.text_text_b);
                        break;
                    case 19:
                        dis1();
                        e1(R.string.text_text_codo);
                        break;
                    case 20:
                        dis0();
                        break;
                    case 21:
                        dis0();
                        break;
                    case 22:
                        dis0();
                        break;
                    case 23:
                        dis0();
                        break;
                    case 24:
                        dis0();
                        break;
                    case 25:
                        dis0();
                        break;
                    case 26:
                        dis0();
                        break;
                    case 27:
                        dis0();
                        break;
                    case 28:
                        dis0();
                        break;
                    case 29:
                        dis0();
                        break;
                    case 30:
                        dis0();
                        break;
                    case 31:
                        dis0();
                        break;
                    case 32:
                        dis0();
                        break;
                    case 33:
                        dis0();
                        break;
                    case 34:
                        dis0();
                        break;
                    case 35:
                        dis0();
                        break;
                    case 36:
                        dis0();
                        break;
                    case 37:
                        dis1();
                        e1(R.string.text_text_tq);
                        break;
                    case 38:
                        dis0();
                        break;
                    case 39:
                        dis0();
                        break;
                    case 40:
                        dis0();
                        break;
                    case 41:
                        dis0();
                        break;
                    case 42:
                        dis0();
                        break;
                    case 43:
                        dis0();
                        break;
                    case 44:
                        dis0();
                        break;
                    case 45:
                        dis0();
                        break;
                    case 46:
                        dis0();
                        break;
                    case 47:
                        dis0();
                        break;
                    case 48:
                        dis0();
                        break;
                    case 49:
                        dis0();
                        break;
                    case 50:
                        dis0();
                        break;
                    case 51:
                        dis0();
                        break;
                    case 52:
                        dis0();
                        break;
                    case 53:
                        dis0();
                        break;
                    case 54:
                        dis0();
                        break;
                    case 55:
                        dis0();
                        break;
                    case 56:
                        dis0();
                        break;
                    case 57:
                        dis0();
                        break;
                    case 58:
                        dis0();
                        break;
                    case 59:
                        dis0();
                        break;
                    case 60:
                        dis0();
                        break;
                    case 61:
                        dis0();
                        break;
                    case 62:
                        dis0();
                        break;
                    case 63:
                        dis0();
                        break;
                    case 64:
                        dis0();
                        break;
                }
            }

            @Override
            public void onNothingSelected(AdapterView<?> adapterView) {

            }
        });
    }
    public void dis0(){
        clean();
        edit_1.setVisibility(View.GONE);
        edit_2.setVisibility(View.GONE);
        edit_3.setVisibility(View.GONE);
    }
    public void dis1(){
        clean();
        edit_1.setVisibility(View.VISIBLE);
        edit_2.setVisibility(View.GONE);
        edit_3.setVisibility(View.GONE);
    }
    public void dis2(){
        clean();
        edit_1.setVisibility(View.VISIBLE);
        edit_2.setVisibility(View.VISIBLE);
        edit_3.setVisibility(View.GONE);
    }
    public void dis3(){
        clean();
        edit_1.setVisibility(View.VISIBLE);
        edit_2.setVisibility(View.VISIBLE);
        edit_3.setVisibility(View.VISIBLE);
    }
    public void e1(int msg){
        edit_1.setHint(msg);
    }
    public void e2(int msg){
        edit_2.setHint(msg);
    }
    public void e3(int msg){
        edit_3.setHint(msg);
    }
    public void clean(){
        edit_1.setText("");
        edit_2.setText("");
        edit_3.setText("");
    }

    @Override
    public void onBackPressed() {
        if (exit){
            Toast.makeText(this, R.string.app_exit_toast, Toast.LENGTH_SHORT).show();
            exit = false;
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    exit = true;
                }
            },2000);
        }else {
            finish();
        }
    }
}
